const vm = new Vue({
    el: '#main',
    data: {
        role: localStorage.getItem('_role') === '0' ? 'fk' : 'fd',
        write: false, // fxj.getSearch().get('write') === '1'
        id: fxj.getSearch().get('id'),
        info: {
            houseInfo: {},
            landlord: {  // 没有评论就传 false 或者 null 或者 ""
                info: {},
                recomment: {},
            },
            tenant: {  // 没有评论就传 false 或者 null 或者 ""
                info: {},
                recomment: {},
            },
        },
        orderId: null,
    },
    methods: {
        goPage,
        nowComment,
        fixImgUrl,
    },
});

function apiready() {
    fxj.fixLayout();
    reqCommentDetail();

}

async function deleteComment(commentId) {
    const res = await ajax({
        url: '',
        data: {},
    });
}

function nowComment() {
    const commentId = fxj.getSearch().get('id');
    if (vm.role === 'fk') {
        goPage(`comment.html?commentId=${commentId}`);

    }
    else if (vm.role === 'fd') {
        goPage(`landlord_comment.html?id=${commentId}`);
    }
}

async function reqCommentDetail() {
    const res = await ajax({
        url: 'home/userComment/getCommentDetail',
        data: {
            id: fxj.getSearch().get('id'),
            type: fxj.getSearch().get('type') // 1 commentId ; 2 orderId
        },
    });
    vm.info = res.data;
    vm.orderId = vm.info.tenant.recomment.order_id;
    if ((!vm.info.landlord || !vm.info.landlord.recomment) && vm.role === 'fd') {
        vm.write = 'fd';
    }
    if ((!vm.info.tenant || !vm.info.tenant.recomment) && vm.role === 'fk') {
        vm.write = 'fk';
    }
}

function fixImgUrl(url) {
    return fxj.fixImgUrl(url);
}